let arr1 = [{
    id: 0,
    name: 'Tom'
  },
  {
    id: 1,
    name: 'Jack'
  },
  {
    id: 2,
    name: 'Jane'
  },
  {
    id: 3,
    name: 'Michale'
  },
]

let arr2 = [{
    id: 3,
    name: 'Michale'
  },
  {
    id: 4,
    name: 'Bob'
  },
  {
    id: 5,
    name: 'Lily'
  },
]

/* 并集 */
const union = arr1.reduce((prev, curr) => {
  if (prev.some(item => item.id === curr.id)) {
    return prev
  } else {
    return [...prev, curr]
  }
}, arr2).sort((a, b) => a.id - b.id)

/* 交集 */
const intersection = arr1.reduce((prev, curr) => {
  return prev.filter(() => prev.some(item => item.id === curr.id))
}, arr2)

console.log(union);
console.log(intersection)
